package com.guigui.gulimall.order.controller;

import com.guigui.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


@RestController
public class RabbitController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String sendMQ(@RequestParam(value = "num",defaultValue = "10") int num) {

        for (int i = 0; i < num; i++) {
            OrderEntity order = new OrderEntity();
            order.setCreateTime(new Date());
            order.setOrderSn("snsnsnsnsnsn");
            if (i % 2 == 0) {
                rabbitTemplate.convertAndSend("gulimall.direct", "gulimall.order", order);
            } else {
                Date date = new Date();
                rabbitTemplate.convertAndSend("gulimall.direct", "gulimall.order", date);
            }
        }
        return "ok";
    }

}
